// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class ColorItem extends cc.Component {

    @property(cc.Node)
    colorNode: cc.Node = null;

    _callback = null;

    _index: number = 0;

    setColor (color: cc.Color, index: number) {
        this.colorNode.color = new cc.Color(color.r, color.g, color.b);
        this._index = index;
    }

    setClickCallback (callback) {
        this._callback = callback;
    }

    onToggleSelect () {
        if (this._callback) {
            this._callback(this._index);
        }
    }
}
